/*
ID: guoxu1
PROG: dualpal
LANG: C++
*/
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <cstring>
using namespace std;

#define cin fin
#define cout fout

bool IsBaseHexPal( int num, int base )
{
	char hex[16] = {0};

	char* h = hex;
	while( num > 0 )
	{
		(*h++) = num % base + '0';
		num /= base;
	}
	h--;
	char* l = hex;
	while( *l == *h )
	{
		l++; h--;
	}
	return ( l >= h );
}

int main()
{
	ifstream fin( "dualpal.in" );
	ofstream fout( "dualpal.out" );

	int N = 0, S = 0;
	cin >> N >> S;

	while( N > 0 )
	{
		S++;
		int count = 0;
		for( int i = 2; i <= 10 && count < 2; i++ )
		{
			if( IsBaseHexPal( S, i ) ) count++;
		}
		if( count == 2 )
		{
			cout << S << endl;
			N--;
		}
	}


	return 0;
}
